<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
session_start();
    if (!isset($_SESSION['Username']) || !isset($_SESSION['Password'])){
        header('Location: index.php');
    }
require_once 'database/profile_handler.php';
require_once 'database/photo_handler.php';
require_once 'database/photo_uploader.php';

	$pf = new profile_handler();

	$pf->get_nama_lengkap($_SESSION['Username']);
					//nama lengkap
	$nama = $pf->result[0];

	//retrieve buat diisi ke form
	$pf->retr_details($_SESSION['Username'], 5);
	//hasilnya
	$birthday = $pf->result[0][0];
	$lokasi = $pf->result[1][0];
	$hobi = $pf->result[2][0];
	$wall_privacy = $pf->result[5][0];

	//cek password
	$pf->get_password($_SESSION['Username']);
	$pass = $pf->result[0];

	if (isset($_POST['SubmitChange'])){
		if ($_POST['OldPassword'] != $pass){
			header('Location: changeprofile.php?gagal=1');
		}
		else{
			$pf->set_nama_lengkap($_SESSION['Username'], $_POST['Name']);
			$pf->set_password($_SESSION['Username'], $_POST['Password']);
			$pf->edit_details($_SESSION['Username'], 1, $_POST['Birthday']);
			$pf->edit_details($_SESSION['Username'], 2, $_POST['Location']);
			$pf->edit_details($_SESSION['Username'], 3, $_POST['Hobby']);
			header('Location: changeprofile.php');
		}
	}
								
							
	if(isset($_POST["ChangeWallPrivacyClick"]))
	{
		$lala = new profile_handler();
		$lala->set_wall_privacy($_SESSION['Username'],$_POST["WallPrivacy"]);
	}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
     <link rel="stylesheet" href="style/style.css" />

	<script type="text/javascript" src="script/validator.js"></script>
	<script type="text/javascript" src="script/calendar.js"></script>
        <script type="text/javascript" src="script/ajax.js"></script>
    
	
</head>
<body onload='document.getElementById("Name").value = "<? echo $nama; ?>";document.getElementById("Birthday").value = "<? echo $birthday; ?>";document.getElementById("Location").value = "<? echo $lokasi; ?>";document.getElementById("Hobby").value = "<? echo $hobi; ?>";HideCalendar();' >
    <div id="container">
        <div id="headerBody">
            <form id="Search" name="Search" method ="GET" action="search_result.php">

                <input type="text" id="SearchBar" name="SearchBar"/>

                <input type="submit" id="SearchOk" name="SearchOk" value="Search"/>
            </form>
            <?php if ($_SESSION['Username'] != null) {
            ?>
                <a id="headerLink" href="javascript:viewHome();" id="headerLink">Home</a>
                <a id="headerLink" href="javascript:showPopupProfile();" id="headerLink">Profile</a>
                <a id="headerLink" href="javascript:viewMessage();" id="headerLink">Message</a>
                <a id="headerLink" href="javascript:viewUploader();" id="headerLink">Uploader</a>
                <a id="headerLink" href="javascript:viewGallery();" id="headerLink">Gallery</a>
                <a href="database/login.php?logout=1" id="logout_link" >Logout</a>
                <a href="chat.php" id="logout_link" >Chat</a>
                <a href="javascript:viewProfile();" id="logout_link" ><?php echo $_SESSION['Username'];?></a>
                <a href="javascript:showNotif('<?php echo $_SESSION['Username']; ?>');" id="headerLink">Notification</a>
                <!-- tampilin jumlah notif -->
            <?php
                require_once 'database/notif_handler.php';

                $notif = new notif_handler();
                $jml = 0;

                $notif->retr_notification($_SESSION['Username']);
                if (count($notif->berita) > 0 && $notif->berita[0] != null) {
                    for ($i = 0; $i < count($notif->berita); $i++) {
                        if ($notif->read[$i] == 0) {
                            $jml++;
                        }
                    }
                    if ($jml > 0)
                        echo "<font color='red'>(" . $jml . ")</font>";
                }
                else {
                    echo "";
                }
            ?>
                <div id="profile_popup">
                </div>
                <div id="notif">
                    <div id="notif2">
                    </div>
                </div>
                <a href="profile.php" id="logout_link" ><?php echo $u; ?></a>
            <?php } else { ?>
                <a href="index.php" id="logout_link" >Login</a>
            <?php
            }
            ?>
        </div>
        <div id=""><img src="images/flickertiew_logo.gif" alt=""/></div>
        <!-- CONTENT dimulai disini -->
        <div id="centerBody">
            <div id ="content">
                <html>
                    <head>
                        <title>Change Profile</title>
                    </head>
                    <body onload='document.getElementById("Name").value = "<? echo $nama; ?>";document.getElementById("Birthday").value = "<? echo $birthday; ?>";document.getElementById("Location").value = "<? echo $lokasi; ?>";document.getElementById("Hobby").value = "<? echo $hobi; ?>";HideCalendar();' >
                        <?php
       if ($_GET['gagal'] == 1){
           ?>
            <script type="text/javascript">alert("Operation failed");</script>
           <?
       }
    ?>
        	<span id="_title2">Hello, <?php echo $nama;?></span>
			<span id="_title" style="float:right; margin-top:5px; margin-right:20px;"><a href="profile.php" alt="">Back</a></span>            
			<br />
			Please fill the form below to change your profile
			<br />
            <div id="form_1" class="group_content">
			<form id = "Info" name = "Info" action = "#" method = "POST" onsubmit='return CekGanti(OldPassword.value,Password.value,Password2.value,Name.value,Birthday.value,Location.value,Hobby.value,LabelOldPasswordSalah,LabelPasswordSalah,LabelPassword2Salah,LabelFullNameSalah,LabelBirthdaySalah,LabelLocationSalah,LabelHobbySalah);'>
            <p>
            <div class="ulabeler"> Password (Old)</div><input type="password" id="OldPassword" class="textarea2" name="OldPassword"/> <label class="Peringatan" id="LabelOldPasswordSalah"> </label>
            <br />
            <div class="ulabeler"> Password</div><input type="password" id="Password" class="textarea2" name="Password"/> <label class="Peringatan" id="LabelPasswordSalah"> </label>
            <br />
            <div class="ulabeler"> Password (Retype)</div><input type="password" class="textarea2" id="Password2" name="Password2"/> <label class="Peringatan" id="LabelPassword2Salah"> </label>
            <br />
            <div class="ulabeler"> Name</div><input type="text" class="textarea2" id="Name" name="Name"/> <label class="Peringatan" id="LabelFullNameSalah"> </label>
            <br />
            <div class="ulabeler"> Birthday</div><input type="text" class="textarea2" id="Birthday" name="Birthday"/><img alt="" src = "script/calendar.jpg" id = "IconCalendar"  onclick = "toggleCalendar('Birthday')" /><label class="Peringatan" id="LabelBirthdaySalah" style="margin-left:50px;"> </label>
			
			<br />
			<table border="1" cellpadding="0" cellspacing="3" id="calendar">
              <tbody>
              <tr>
                <td class="today" colspan="5" id="todayday" onClick="">This is calendar popup</td>
                <td align="right" colspan="2"><a href="javascript:HideCalendar();"><b>Hide</b></a></td>
              </tr>
              <tr>
                <td colspan="7" valign="middle">
                <!-- Month combo box -->
                <select id="month" onChange="newCalendar()">
                    <option value="Januari">January</option>
                    <option value="Februari">February</option>
                    <option value="Maret">March</option>
                    <option value="April">April</option>
                    <option value="Mei">May</option>
                    <option value="Juni">June</option>
                    <option value="Juli">July</option>
                    <option value="Agustus">August</option>
                    <option value="September">September</option>
                    <option value="Oktober">October</option>
                    <option value="November">November</option>
                    <option value="Desember">December</option>
                </select>
                <!-- Year combo box -->
                <select id="year" onChange="newCalendar()">
                    <option value="1951">1951</option>
                    <option value="1952">1952</option>
                    <option value="1953">1953</option>
                    <option value="1954">1954</option>
                    <option value="1955">1955</option>
                    <option value="1956">1956</option>
                    <option value="1957">1957</option>
                    <option value="1958">1958</option>
                    <option value="1959">1959</option>
                    <option value="1950">1960</option>

                    <option value="1961">1961</option>
                    <option value="1962">1962</option>
                    <option value="1963">1963</option>
                    <option value="1964">1964</option>
                    <option value="1965">1965</option>
                    <option value="1966">1966</option>
                    <option value="1967">1967</option>
                    <option value="1968">1968</option>
                    <option value="1969">1969</option>
                    <option value="1970">1970</option>

                    <option value="1971">1971</option>
                    <option value="1972">1972</option>
                    <option value="1973">1973</option>
                    <option value="1974">1974</option>
                    <option value="1975">1975</option>
                    <option value="1976">1976</option>
                    <option value="1977">1977</option>
                    <option value="1978">1978</option>
                    <option value="1979">1979</option>
                    <option value="1980">1980</option>

                    <option value="1981">1981</option>
                    <option value="1982">1982</option>
                    <option value="1983">1983</option>
                    <option value="1984">1984</option>
                    <option value="1985">1985</option>
                    <option value="1986">1986</option>
                    <option value="1987">1987</option>
                    <option value="1988">1988</option>
                    <option value="1989">1989</option>
                    <option value="1990">1990</option>

                    <option value="1991">1991</option>
                    <option value="1992">1992</option>
                    <option value="1993">1993</option>
                    <option value="1994">1994</option>
                    <option value="1995">1995</option>
                    <option value="1996">1996</option>
                    <option value="1997">1997</option>
                    <option value="1998">1998</option>
                    <option value="1999">1999</option>
                    <option value="2000">2000</option>

                    <option value="2001">2001</option>
                    <option value="2002">2002</option>
                    <option value="2003">2003</option>
                    <option value="2004">2004</option>
                    <option value="2005">2005</option>
                    <option value="2006">2006</option>
                    <option value="2007">2007</option>
                    <option value="2008">2008</option>
                    <option value="2009">2009</option>
                    <option value="2010">2010</option>
                    <option value="2011">2011</option>
                </select>

                </td>
              </tr>
              <tr class="days">
                <!-- Generate column for each day. -->
                <td>Sunday</td>
                <td>Monday</td>
                <td>Tuesday</td>
                <td>Wednesday</td>
                <td>Thursday</td>
                <td>Friday</td>
                <td>Saturday</td>
              </tr>
              </tbody>

              <!-- Generate today day. -->
              <tbody class="dates" id="dayList" onClick="getDate('')" valign="middle">
              <!-- Generate grid for individual days. -->
              <tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
              <tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
              <tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
              <tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
              <tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
              <tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
                </tbody>

            </table>
			
            <br />
           <div class="ulabeler">Location</div><input type="text" class="textarea2" id="Location" name="Location"/> <label class="Peringatan" id="LabelLocationSalah"> </label>
           <br />
           <div class="ulabeler">Hobby</div><input type="text" class="textarea2" id="Hobby" name="Hobby"/> <label class="Peringatan" id="LabelHobbySalah"> </label>
           <br />
           <br />
           <input type="submit" id ="kodok" name="SubmitChange" value="Change"/>
            </p>
            </form>
            </div>
			<div id="form_2" class="group_content">
			<form enctype="multipart/form-data" id="ChangePhoto" method="POST" action="database/ganti_profpic.php" onsubmit='return CekPhotoURL(PhotoChooser.value,LabelPhotoSalah);'>
			<p>
			This is for changing the profile picture with the new one
			<br />
				<input type="file" id="PhotoChooser" name="PhotoChooser" /><label class="Peringatan" id="LabelPhotoSalah"> </label>
				<br/>
				<input type = "submit" id="ChangePhotoClick" name="ChangePhotoClick" value="Change Photo"/>
			</p>
			</form>
			</div>
            <div id="form_3" class="group_content">
			<form id="ChangeWallPrivacy" name="ChangeWallPrivacy" method="POST" action="#" onsubmit=''>
			<p>
			This is for wall privacy
			<br />
				<select id="WallPrivacy" name="WallPrivacy">
					<option value="all members" <?php if($wall_privacy=="all members")echo"selected";?>> All Members </option>
					<option value="just followers" <?php if($wall_privacy=="just followers")echo"selected";?>> Just Followers </option>
					<option value="only me" <?php if($wall_privacy=="only me")echo"selected";?>> Only Me </option>
				</select>
				<br/>
				<input type = "submit" id="ChangeWallPrivacyClick" name="ChangeWallPrivacyClick" value="Change Wall Privacy"/>
			</p>
			</form>
			</div>
                    </body>
                </html>

        </div>
        </div>
        <div id="footerBody" class="group_content">
                <div id="footer" align="center">
                    Copyright &copy; 2011<br/>
                    Created by <a href="http://www.facebook.com/Gunawan.Robert" id="headerLink">Robert Gunawan</a>
                                                    , <a href="http://www.facebook.com/danz3m" id="headerLink">Danang Tri Massandy</a>,
                    <a href="http://www.facebook.com/achmad.giovani" id="headerLink">Achmad Giovani</a>
                </div>
            

                    
            </div> 
        </div>
     </body>
 </html>

